package com.pubinfo.passbook.api.controller.auth;

import com.pubinfo.passbook.common.entity.TSystemPermission;
import com.pubinfo.passbook.common.model.dto.system.PermissionParam;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TSystemPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "permission/manager")
@Api(tags = "权限管理")
@Slf4j
public class PermissionController {
  
  @Resource
  private TSystemPermissionService permissionService;
  
  @PostMapping("save")
  @ApiOperation("新增权限")
  public JsonResult<Boolean> savePermission(@RequestBody TSystemPermission permission) {
    return JsonResult.success(permissionService.save(permission));
  }
  
  @DeleteMapping("remove")
  @ApiOperation("删除权限")
  public JsonResult<Boolean> removePermission(Integer permId) {
    return JsonResult.success(permissionService.removeById(permId));
  }
  
  @PostMapping("list")
  @ApiOperation("查询权限列表")
  public JsonResult<MyPage<TSystemPermission>> listPermissions(@RequestBody PermissionParam param) {
    return JsonResult.success(new MyPage(permissionService.listPermissions(param)));
  }
}
